<!DOCTYPE html>
<!--
  ~ Copyright (C) 2018 justlive1
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  ~ in compliance with the License. You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software distributed under the License
  ~ is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  ~ or implied. See the License for the specific language governing permissions and limitations under
  ~ the License.
  -->
<html lang="zh-cn">
<head>
  <meta charset="UTF-8">
  <title>注册</title>
  <meta name="viewport"
        content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
  <link rel='Shortcut Icon' type='image/x-icon' href="/static/image/window.ico">
  <link href="static/css/default.css" rel="stylesheet">
</head>
<body>
<div id="win10-login">
  <div style="min-height: 20px"></div>
  <div id="win10-login-box">
    <div class="win10-login-box-square">
      <img src="static/image/avatar.jpg" class="content"/>
    </div>
    <p style="font-size: 24px; color: white; text-align: center">REGISTER</p>
    <form class="layui-form" action="/register" method="post">
      <input type="text" placeholder="请输入账号" lay-verify="required" class="login-username"
             name="username"/>
      <input type="password" placeholder="请输入密码" lay-verify="required" class="login-username"
             name="password"/>
      <input type="password" placeholder="请输入确认密码" lay-verify="required" class="login-password"
             name="repassword"/>
      <input type="submit" lay-submit lay-filter="register" value="注册" class="login-submit"/>
      <div class="login-tip-info">已有账号？<a href="/login.html">立即登录</a></div>
    </form>

  </div>
</div>

<script type="text/javascript" src="static/js/layui-v2.3.0/layui.js"></script>
<script type="text/javascript">
  layui.use(['form', 'layer'], function () {
    layui.form.on('submit(register)', function (data) {
      if (data.field.password != data.field.repassword) {
        layui.layer.msg("密码输入不一致");
        return false;
      }
      var param = {username: data.field.username, password: data.field.password};
      layui.$.ajax({
        url: data.form.action,
        type: 'post',
        contentType: "application/json",
        data: JSON.stringify(param),
        success: function (resp) {
          if (resp.success) {
            layui.layer.msg("注册成功！");
          } else {
            layui.layer.msg(resp.message);
          }
        },
        error: function () {
          layui.layer.msg("服务器繁忙，请稍后重试！");
        }
      });
      return false;
    });
  });
</script>
</body>
</html>
